package pe.com.rimac.portal.service.facturacion.trama;

import org.apache.commons.lang.StringUtils;

public class Header
{
	private static final String HEADER_OPEN = "<HEADER>";
	private static final String HEADER_CLOSE = "</HEADER>";
	private static final String IDTRANSACCION = "<ITRANSACCION>?</ITRANSACCION>";
	private static final String TOKEN = "<TOKEN>?</TOKEN>";
	private static final String ID = "<ID>?</ID>";
	private String idTransaccion;
	private String token;
	private String id;

	public void setIdTransaccion(String idTransaccion)
	{
		this.idTransaccion = idTransaccion;
	}

	public void setToken(String token)
	{
		this.token = token;
	}

	public void setId(String id)
	{
		this.id = id;
	}

	private String getIdTransaccion()
	{
		return idTransaccion;
	}

	private String getToken()
	{
		return token;
	}

	private String getId()
	{
		return id;
	}

	/**
	 * Construye la cabecera de la trama a enviar.
	 * 
	 * <pre>
	 * <HEADER>
	 *  <IDTRANSACCION></IDTRANSACCION>
	 *  <TOKEN></TOKEN>
	 *  <ID></ID>
	 * </HEADER>
	 * </pre>
	 * 
	 * @return
	 */
	public String build()
	{
		StringBuilder builder = new StringBuilder();
		builder.append(HEADER_OPEN);
		builder.append(StringUtils.replace(IDTRANSACCION, "?", getIdTransaccion()));
		builder.append(StringUtils.replace(TOKEN, "?", getToken()));
		builder.append(StringUtils.replace(ID, "?", getId()));
		builder.append(HEADER_CLOSE);
		return builder.toString();
	}
}